package chapter6;
/****************************************************************
 * Author：icynlau
 * Description: 估算PI
运算结果
i                      m(i)
==============
1                   4.0000
101                 3.1515
201                 3.1466
301                 3.1449
401                 3.1441
501                 3.1436
601                 3.1433
701                 3.1430
801                 3.1428
901                 3.1427

 * Date:2021/4/4
 * ***************************************************************
 */
public class exc6_14 {

	public static double compute(int n) {
		
		double sum=0;
		
		for(int i=1;i<=n;i++) {
			
			sum=sum+Math.pow(-1, i+1)/(2.0*i-1.0);
			
		}
		
		return 4.0*sum;
		
	}

	
	public static void main(String[] args) {
		
		System.out.print("i                      m(i)\n");
		System.out.print("==============\n");
		
		
		for(int i=0;i<10;i++) {
			
			System.out.printf("%-3d               %8.4f\n", 100*i+1,compute( 100*i+1));
			
		}
		
	}
	
}
